package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.SellerPopupPresenter;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class SellerPopupView extends DialogBox implements SellerPopupPresenter.Display{
	private TextBox userName, password;
	private Button btnSave, btnCancel;
	private TextBox sellerName, lastName, telephone, address, city, zp;
	private Label lblWPassword, lblWUserName, lblWAddress, lblWTelephone;
	private Label lblWLastName, lblWName, lblWCity, lblWCP;
	
	public SellerPopupView() {
	    FlexTable flexTable = new FlexTable();
	    flexTable.setSize("450px", "260px");
	    setWidget(flexTable);
	    
	    Label lblName = new Label(CloudMobile.constants.name()+":");
	    lblName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(0, 0, lblName);	    
	    flexTable.getCellFormatter().setHeight(0, 0, "20px");
	    flexTable.getCellFormatter().setWidth(0, 0, "180px");
	    lblName.setWidth("180px");
	    
	    sellerName = new TextBox();
	    flexTable.setWidget(0, 1, sellerName);
	    flexTable.getCellFormatter().setHeight(0, 1, "20px");
	    flexTable.getCellFormatter().setWidth(0, 1, "150px");
	    sellerName.setSize("95%", "100%");
	    
	    lblWName = new Label(CloudMobile.constants.wInvalidate());
	    lblWName.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(0, 2, lblWName);
	    lblWName.setWidth("120px");
	    lblWName.setVisible(false);
	    
	    Label lblLastName = new Label(CloudMobile.constants.lastName()+":");
	    lblLastName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(1, 0, lblLastName);	    
	    flexTable.getCellFormatter().setHeight(1, 0, "20px");
	    flexTable.getCellFormatter().setWidth(1, 0, "180px");
	    lblLastName.setWidth("180px");
	    
	    lastName = new TextBox();
	    flexTable.setWidget(1, 1, lastName);
	    flexTable.getCellFormatter().setHeight(1, 1, "20px");
	    flexTable.getCellFormatter().setWidth(1, 1, "150px");
	    lastName.setSize("95%", "100%");
	    
	    lblWLastName = new Label(CloudMobile.constants.wInvalidate());
	    lblWLastName.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(1, 2, lblWLastName);
	    lblWLastName.setWidth("120px");
	    lblWLastName.setVisible(false);
	    
	    Label lblAddress = new Label(CloudMobile.constants.address()+":");
	    lblAddress.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(2, 0, lblAddress);	    
	    lblAddress.setWidth("180px");
	    flexTable.getCellFormatter().setHeight(2, 0, "20px");
	    flexTable.getCellFormatter().setWidth(2, 0, "180px");
	    
	    address = new TextBox();
	    flexTable.setWidget(2, 1, address);
	    flexTable.getCellFormatter().setHeight(2, 1, "20px");
	    flexTable.getCellFormatter().setWidth(2, 1, "150px");
	    address.setSize("95%", "100%");
	    
	    lblWAddress = new Label(CloudMobile.constants.wInvalidate());
	    lblWAddress.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(2, 2, lblWAddress);
	    lblWAddress.setWidth("120px");
	    lblWAddress.setVisible(false);
	    
	    Label lblCity = new Label(CloudMobile.constants.city()+":");
	    lblCity.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(3, 0, lblCity);	    
	    lblCity.setWidth("180px");
	    flexTable.getCellFormatter().setHeight(3, 0, "20px");
	    flexTable.getCellFormatter().setWidth(3, 0, "180px");
	    
	    city = new TextBox();
	    flexTable.setWidget(3, 1, city);
	    flexTable.getCellFormatter().setHeight(3, 1, "20px");
	    flexTable.getCellFormatter().setWidth(3, 1, "150px");
	    city.setSize("95%", "100%");
	    
	    lblWCity = new Label(CloudMobile.constants.wInvalidate());
	    lblWCity.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(3, 2, lblWCity);
	    lblWCity.setWidth("120px");
	    lblWCity.setVisible(false);
	    
	    Label lblCP = new Label(CloudMobile.constants.cp()+":");
	    lblCP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(4, 0, lblCP);	    
	    lblCP.setWidth("180px");
	    flexTable.getCellFormatter().setHeight(4, 0, "20px");
	    flexTable.getCellFormatter().setWidth(4, 0, "180px");
	    
	    zp = new TextBox();
	    flexTable.setWidget(4, 1, zp);
	    flexTable.getCellFormatter().setHeight(4, 1, "20px");
	    flexTable.getCellFormatter().setWidth(4, 1, "150px");
	    zp.setSize("95%", "100%");
	    
	    lblWCP = new Label(CloudMobile.constants.wInvalidate());
	    lblWCP.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(4, 2, lblWCP);
	    lblWCP.setWidth("120px");
	    lblWCP.setVisible(false);
	    
	    Label lblTelephone = new Label(CloudMobile.constants.telephone()+":");
	    lblTelephone.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(5, 0, lblTelephone);	    
	    flexTable.getCellFormatter().setHeight(5, 0, "20px");
	    flexTable.getCellFormatter().setWidth(5, 0, "180px");
	    lblTelephone.setWidth("180px");
	    
	    telephone = new TextBox();
	    flexTable.setWidget(5, 1, telephone);
	    flexTable.getCellFormatter().setHeight(5, 1, "20px");
	    flexTable.getCellFormatter().setWidth(5, 1, "150px");
	    telephone.setSize("95%", "100%");
	    
	    lblWTelephone = new Label(CloudMobile.constants.wInvalidate());
	    lblWTelephone.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(5, 2, lblWTelephone);
	    lblWTelephone.setWidth("120px");
	    lblWTelephone.setVisible(false);
	    
	    Label lblUserName = new Label(CloudMobile.constants.userName()+":");
	    lblUserName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(6, 0, lblUserName);	    
	    flexTable.getCellFormatter().setHeight(7, 0, "20px");
	    flexTable.getCellFormatter().setWidth(7, 0, "180px");
	    lblUserName.setWidth("180px");
	    
	    userName = new TextBox();
	    flexTable.setWidget(6, 1, userName);
	    flexTable.getCellFormatter().setHeight(7, 1, "20px");
	    flexTable.getCellFormatter().setWidth(7, 1, "150px");
	    userName.setSize("95%", "100%");
	    
	    lblWUserName = new Label(CloudMobile.constants.wInvalidate());
	    lblWUserName.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(6, 2, lblWUserName);
	    lblWUserName.setWidth("120px");
	    lblWUserName.setVisible(false);
	    
	    Label lblPassword = new Label(CloudMobile.constants.password()+":");
	    lblPassword.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.setWidget(7, 0, lblPassword);
	    flexTable.getCellFormatter().setHeight(8, 0, "20px");
	    flexTable.getCellFormatter().setWidth(8, 0, "180px");
	    lblPassword.setWidth("180px");
	    
	    password = new TextBox();
	    flexTable.setWidget(7, 1, password);
	    flexTable.getCellFormatter().setHeight(8, 1, "20px");
	    flexTable.getCellFormatter().setWidth(8, 1, "150px");
	    password.setSize("95%", "100%");
	    
	    lblWPassword = new Label(CloudMobile.constants.wInvalidate());
	    lblWPassword.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(7, 2, lblWPassword);
	    lblWPassword.setWidth("120px");
	    lblWPassword.setVisible(false);
	    
	    Grid grid = new Grid(1, 2);
	    flexTable.setWidget(8, 1, grid);
	    grid.setSize("210", "34");
	    
	    btnCancel = new Button(CloudMobile.constants.cancel());
	    grid.setWidget(0, 1, btnCancel);
	    btnCancel.setSize("100px", "28px");
	    
	    btnSave = new Button(CloudMobile.constants.save());
	    grid.setWidget(0, 0, btnSave);
	    btnSave.setSize("100px", "28px");
	    grid.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
	    grid.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    grid.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
	    grid.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
	    setSize("473px", "312px");
	    setGlassEnabled(true);
	    center();
	    show();
	}

	@Override
	public HasValue<String> getUserName() {
		return userName;
	}

	@Override
	public HasValue<String> getPassword() {
		return password;
	}

	@Override
	public HasClickHandlers getSaveButton() {
		return btnSave;
	}

	@Override
	  public void hide() {
	    super.hide();
	  }

	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public HasClickHandlers getCancelButton() {
		return btnCancel;
	}

	@Override
	public void setTextPopup(String text) {
		this.setText(text);	
	}

	@Override
	public String getTextPopup() {
		return this.getText();
	}

	@Override
	public void disableUserName() {
		userName.setEnabled(false);	
	}
	
	@Override
	public void disableName() {
		sellerName.setEnabled(false);	
	}
	
	@Override
	public void disableLastName() {
		lastName.setEnabled(false);	
	}

	@Override
	public void enableSave(boolean flag) {
		btnSave.setEnabled(flag);	
	}

	@Override
	public HasValue<String> getName() {
		return sellerName;
	}

	@Override
	public HasValue<String> getLastName() {
		return lastName;
	}

	@Override
	public HasValue<String> getTelephone() {
		return telephone;
	}

	@Override
	public HasValue<String> getAddress() {
		return address;
	}

	@Override
	public void setVisibeWName(boolean visible) {
		lblWName.setVisible(visible);	
	}

	@Override
	public void setVisibeWLastName(boolean visible) {
		lblWLastName.setVisible(visible);
		
	}

	@Override
	public void setVisibeWTel(boolean visible) {
		lblWTelephone.setVisible(visible);
		
	}

	@Override
	public void setVisibeWAddress(boolean visible) {
		lblWAddress.setVisible(visible);
		
	}

	@Override
	public void setVisibeWUserName(boolean visible) {
		lblWUserName.setVisible(visible);
		
	}

	@Override
	public void setVisibeWUserPass(boolean visible) {
		lblWPassword.setVisible(visible);
	}

	@Override
	public HasValue<String> getZP() {
		return zp;
	}

	@Override
	public HasValue<String> getCity() {
		return city;
	}

	@Override
	public void setVisibeWCP(boolean visible) {
		lblWCP.setVisible(visible);
		
	}

	@Override
	public void setVisibeWCity(boolean visible) {
		lblWCity.setVisible(visible);
		
	}
}
